package com.atguigu.ggkt.vod.service.impl;

import com.atguigu.ggkt.model.vod.VideoVisitor;
import com.atguigu.ggkt.vo.vod.VideoVisitorCountVo;
import com.atguigu.ggkt.vo.vod.VideoVisitorVo;
import com.atguigu.ggkt.vod.mapper.VideoVisitorMapper;
import com.atguigu.ggkt.vod.service.VideoVisitorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * <p>
 * 视频来访者记录表 服务实现类
 * </p>
 *
 * @author lxx
 * @since 2022-07-01
 */
@Service
public class VideoVisitorServiceImpl extends ServiceImpl<VideoVisitorMapper, VideoVisitor> implements VideoVisitorService {
    @Override
    public Map<String, Object> findCount(Long courseId, String startDate, String endDate) {
        List<VideoVisitorCountVo> videoVisitorVoList = baseMapper.findCount(courseId, startDate,endDate);
        Map<String, Object> map = new HashMap<>(16);
        // 1.创建日期集合
        List<String> dateList = new ArrayList<>();
        // 2.创建日期对应数据集合
        List<Integer> countList = new ArrayList<>();
        // 3.封装数据
        videoVisitorVoList.forEach(videoVisitorVo -> {
            dateList.add(videoVisitorVo.getJoinTime());
            countList.add(videoVisitorVo.getUserCount());
        });
        map.put("xData", dateList);
        map.put("yData", countList);
        return map;
    }
}
